
***********************************************
* Rwanda provider study
***********************************************

***********************************************
* Contents
***********************************************

	* (0.0) Set up
	* (0.1) Prepare data
	* (0.2) Mediation analysis: staff presence
	* (0.3) Mediation analysis: management indicator
	* (0.4) Mediation analysis: waiting rooms
	* (0.5) Mediation analysis: general operations
	
***********************************************
* (0.0) Set up
***********************************************
	
	clear all
	clear matrix
	set mem 250m
	set matsize 1000
	set more off
	tempfile temp1
	pause on
    eststo clear
	
	cd "C:\Users\Diana\Dropbox\RWA_P4P\SPA\do_files"
	
	* Define file globals
	do rwanda_global_define.do

    cap log close
    log using `"$d_out\logs\logresults_`c(current_date)'.txt"', text replace
	
***********************************************
* (0.1) Prepare data
***********************************************
use "$d_interm\del_outcomes", clear
merge 1:1 facil using "$r_fac_controls", nogen
merge 1:1 facil using "$d_interm\inputs", nogen
merge 1:1 facil using "$d_interm\fees", nogen
merge 1:1 facil using "$d_interm\anc_outcomes", nogen
merge 1:1 facil using "$d_interm\manage", nogen
merge 1:1 facil using "$d_interm\hiv_outcomes", nogen
merge 1:1 facil using "$d_interm\manage_mult", nogen

local province_control="province_south province_east province_west"
local clinic_control="has_genout has_anc has_tb has_hiv has_inmed"
local other_control="funds_equity funds_emp funds_ins funds_pool"

recode chw* q_supplies q_sup_oth q_med q_sup_nb fee_del_any q_benefits funds_ins q_qual q_accred q_opin (100=1)


* Dropping hospitals
drop if factype==1

drop if treat==2 /* Restrict to control and treatment only */
	
	
gen fac_births=totr01/39.2/1.15
global fac_births_desc "\# institutional deliveries/birth"
lab var fac_births "$fac_births_desc"

***********************************************
* (0.2) Mediation analysis: staff presence
***********************************************

	local M="fancppc"
	local T="treatment"
	local Y="fac_births"
	local x="private logcatch `clinic_control' `other_control' `province_control'"

	medeff (regress `M' `T' `x' health_post) (regress `Y' `T' `M' `x' health_post ) , treat(`T') mediate(`M') level(95)	
	medsens (regress `M' `T' `x' health_post) (regress `Y' `T' `M' `x' health_post), eps(.01) med(`M') treat(`T') sims(1000) graph
	pause
	
	
***********************************************
* (0.3) Mediation analysis: management indicator
***********************************************

	
	local M="manage_mult_pca"
	
	medeff (regress `M' `T' `x' health_post) (regress `Y' `T' `M' `x' health_post ) , treat(`T') mediate(`M') level(95)
	medsens (regress `M' `T' `x' health_post) (regress `Y' `T' `M' `x' health_post), eps(.01) med(`M') treat(`T') sims(1000) graph
	pause

***********************************************
* (0.4) Mediation analysis: waiting rooms
***********************************************

	local M="m_wait"
	
	medeff (regress `M' `T' `x' health_post) (regress `Y' `T' `M' `x' health_post ) , treat(`T') mediate(`M') level(95)
	medsens (regress `M' `T' `x' health_post) (regress `Y' `T' `M' `x' health_post), eps(.01) med(`M') treat(`T') sims(1000) graph
	pause
	
***********************************************
* (0.5) Mediation analysis: general operations
***********************************************

	gen idx_gman_eqpca=1/3*cl_clean_pca+1/3*manage_mult_pca+1/3*m_wait
	
	local M="idx_gman_eqpca"

	medeff (regress `M' `T' `x' health_post) (regress `Y' `T' `M' `x' health_post ) , treat(`T') mediate(`M') level(95)
	medsens (regress `M' `T' `x' health_post) (regress `Y' `T' `M' `x' health_post), eps(.01) med(`M') treat(`T') sims(1000) graph
	
